package com.xerland.tbootstrap.utils;

import android.content.Context;

/**
 * Fileame: com.xerland.tbootstrap.utils
 * Desription:
 * Class and methods:
 * <p>
 * Author: Anson Chan
 * Copyright: 2016 Xerland Co. Ltd. All rights reserved.
 * Contact:    anson_chan@xerland.com
 * Deffield    updated: Updated
 */
public class TopicFormater {

    public static final String UserPrefix = "/user/";
    public static final String UserTopicDivider = "@";
    public static final String RequestSuffix = "/request";
    public static final String ResponseSuffix = "/response";

    private Context context;
    private SpfManager spfManager;
    private String selfId;
    private String peerId;
    private String baseTopic;


    public TopicFormater(Context context) {
        this.context = context;
        spfManager = new SpfManager(context);
        selfId = UserPrefix+spfManager.loadUserId();
        peerId = UserPrefix+spfManager.loadPeerId();
        baseTopic = spfManager.loadBaseTopic();

    }

    public String getSubFrom(String content) {
        return baseTopic+content+UserTopicDivider+peerId;
    }

    public String getSubToFrom(String content) {
        return selfId+UserTopicDivider+baseTopic+content+UserTopicDivider+peerId;
    }

    public String getSubToFromX(String content) {
        return selfId+UserTopicDivider+baseTopic+content+ResponseSuffix+UserTopicDivider+peerId;
    }

    public String getPubFrom(String content) {
        return baseTopic+content+UserTopicDivider+selfId;
    }

    public String getPubToFrom(String content) {
        return peerId+UserTopicDivider+baseTopic+content+UserTopicDivider+selfId;
    }

    public String getPubToFromX(String content) {
        return peerId+UserTopicDivider+baseTopic+content+RequestSuffix+UserTopicDivider+selfId;
    }

}
